<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML>
<html>
<head>
<%@include file="/WEB-INF/css.jsp" %>
<%@include file="/WEB-INF/javascript.jsp" %>
<title>Padgett Resource Management - Dashboard</title>
<script>
$(document).ready(function(){
	$('#ServiceFiltersContainer').buttonset().change(function(){
		$('#ServicesContainer').empty();
		// Collect all filters, get clients by filters.
		var filters={
		};
		$('#ServiceFiltersContainer :checked').each(function(){
			filters[$(this).attr('name')]=true;
		});
		$.ajax({
			url:"/AjaxGetAllServices",
			type:"GET",
			data:filters,
			dataType:"json",
			success:function(data,status,xhr){
				var services=data.data;
				var servicesContainer=$('#ServicesContainer');
				if(services!=null&&services.length>0){
					for(var i=0;i<services.length;i++){
						servicesContainer.append('<div class="ServiceCard">'+
						'<div class="ServiceCardInfo">'+
						'<div style="float:left;width:100%;font: bold 1.3em Verdana, Geneva, sans-serif;padding-bottom:10px;"><a href="/GetClient?clientId='+services[i].ClientId+'">'+(services[i].ClientName==undefined?"":services[i].ClientName)+'</a></div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Type:</span> <a href="/GetService?serviceId='+services[i].serviceId+'">'+(services[i].Type==undefined?"":services[i].Type)+'</a></div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Fee:</span> $'+(services[i].Fee==undefined?"":services[i].Fee)+'</div>'+
						'<div style="float:left;width:33%;">'+(services[i].Billable!=undefined&&services[i].Billable==true?"Billable":"Non-Billable")+'</div>'+
						'<div style="float:left;width:33%;">'+(services[i].Billed!=undefined&&services[i].Billed==true?"Billed":"Unbilled")+'</div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Due Date:</span> '+(services[i].DueDate==undefined?"":services[i].DueDate)+'</div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Accountant:</span> '+(services[i].AccountantName==undefined?"":services[i].AccountantName)+'</div>'+
						(services[i].CompletedDate!=undefined?'<div class="SuccessSmall">Completed</div>':'<div class="ErrorSmall">Incomplete</div>')+
						'</div></div>');
					}
				}else{
					servicesContainer.append('<div class="ServiceCard"><div class="Warning">No Services Found</div></div>');
				}
			},
			error:function(xhr,status,error){
				alert('Error:'+error);
			}
		});
	});
	$('#InvoiceFiltersContainer').buttonset().change(function(){
		$('#InvoicesContainer').empty();
		// Collect all filters, get clients by filters.
		var filters={
		};
		$('#InvoiceFiltersContainer :checked').each(function(){
			filters[$(this).attr('name')]=true;
		});
		$.ajax({
			url:"/AjaxGetAllInvoices",
			type:"GET",
			data:filters,
			dataType:"json",
			success:function(data,status,xhr){
				var invoices=data.data;
				var invoicesContainer=$('#InvoicesContainer');
				if(invoices!=null&&invoices.length>0){
					for(var i=0;i<invoices.length;i++){
						invoicesContainer.append('<div class="InvoiceCard">'+
						'<div class="InvoiceCardInfo">'+
						'<div style="float:left;width:100%;font: bold 1.3em Verdana, Geneva, sans-serif;padding-bottom:5px;"><a href="/GetClient?clientId='+invoices[i].ClientId+'">'+(invoices[i].ClientName==undefined?"":invoices[i].ClientName)+'</a></div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Invoice Number: </span><a href="/GetInvoice?invoiceId='+invoices[i].invoiceId+'">'+(invoices[i].InvoiceNumber==undefined?"":invoices[i].InvoiceNumber)+'</a></div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Items: </span>'+(invoices[i].Items==undefined?"0":invoices[i].Items)+'</div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Total Amount: </span>$'+(invoices[i].TotalAmount!=undefined?invoices[i].TotalAmount:"0")+'</div><div style="float:left;width:33%;">&nbsp;</div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Issued Date: </span>'+(invoices[i].IssuedDate==undefined?"":invoices[i].IssuedDate)+'</div>'+
						'<div style="float:left;width:33%;"><span class="kheader">Accountant: </span>'+(invoices[i].AccountantName==undefined?"":invoices[i].AccountantName)+'</div>'+(invoices[i].FullyPaidDate!=undefined?'<div class="PaidMessage">'+invoices[i].FullyPaidDate+'</div>':'<div class="ErrorSmall">Unpaid</div>')+
						'</div></div>');
					}
				}else{
					invoicesContainer.append('<div class="InvoiceCard"><div class="Warning">No Invoices Found</div></div>');
				}
			},
			error:function(xhr,status,error){
				alert('Error:'+error);
			}
		});
	});
	$.ajax({
	url:"/AjaxGetAllServices",
	type:"GET",
	data:{
		FilterCompleted:true,
		FilterIncomplete:true,
		FilterBillable:true,
		FilterNonBillable:true
	},
	dataType:"json",
	success:function(data,status,xhr){
		var services=data.data;
		var servicesContainer=$('#ServicesContainer');
		if(services!=null&&services.length>0){
			for(var i=0;i<services.length;i++){
				servicesContainer.append('<div class="ServiceCard">'+
				'<div class="ServiceCardInfo">'+
				'<div style="float:left;width:100%;font: bold 1.3em Verdana, Geneva, sans-serif;padding-bottom:5px;"><a href="/GetClient?clientId='+services[i].ClientId+'">'+(services[i].ClientName==undefined?"":services[i].ClientName)+'</a></div>'+
				'<div style="float:left;width:33%;"><span class="kheader">Type:</span> <a href="/GetService?serviceId='+services[i].serviceId+'">'+(services[i].Type==undefined?"":services[i].Type)+'</a></div>'+
				'<div style="float:left;width:33%;"><span class="kheader">Fee:</span> $'+(services[i].Fee==undefined?"":services[i].Fee)+'</div>'+
				'<div style="float:left;width:33%;">'+(services[i].Billable!=undefined&&services[i].Billable==true?"Billable":"Non-Billable")+'</div>'+
				'<div style="float:left;width:33%;">'+(services[i].Billed!=undefined&&services[i].Billed==true?"Billed":"Unbilled")+'</div>'+
				'<div style="float:left;width:33%;"><span class="kheader">Due Date:</span> '+(services[i].DueDate==undefined?"":services[i].DueDate)+'</div>'+
				'<div style="float:left;width:33%;"><span class="kheader">Accountant:</span> '+(services[i].AccountantName==undefined?"":services[i].AccountantName)+'</div>'+
				(services[i].CompletedDate!=undefined?'<div class="SuccessSmall">Completed</div>':'<div class="ErrorSmall">Incomplete</div>')+
				'</div></div>');
			}
		}else{
			servicesContainer.append('<div class="ServiceCard"><div class="Warning">No Services Found</div></div>');
		}
	},
	error:function(xhr,status,error){
		//alert('Error:'+error);
	}
});
	$.ajax({
		url:"/AjaxGetAllInvoices",
		type:"GET",
		data:{
			FilterPaid:true,
			FilterUnpaid:true
		},
		dataType:"json",
		success:function(data,status,xhr){
			var invoices=data.data;
			var invoicesContainer=$('#InvoicesContainer');
			if(invoices!=null&&invoices.length>0){
				for(var i=0;i<invoices.length;i++){
					invoicesContainer.append('<div class="InvoiceCard">'+
					'<div class="InvoiceCardInfo">'+
					'<div style="float:left;width:100%;font: bold 1.3em Verdana, Geneva, sans-serif;padding-bottom:5px;"><a href="/GetClient?clientId='+invoices[i].ClientId+'">'+(invoices[i].ClientName==undefined?"":invoices[i].ClientName)+'</a></div>'+
					'<div style="float:left;width:33%;"><span class="kheader">Invoice Number: </span><a href="/GetInvoice?invoiceId='+invoices[i].invoiceId+'">'+(invoices[i].InvoiceNumber==undefined?"":invoices[i].InvoiceNumber)+'</a></div>'+
					'<div style="float:left;width:33%;"><span class="kheader">Items: </span>'+(invoices[i].Items==undefined?"0":invoices[i].Items)+'</div>'+
					'<div style="float:left;width:33%;"><span class="kheader">Total Amount: </span>$'+(invoices[i].TotalAmount!=undefined?invoices[i].TotalAmount:"0")+'</div><div style="float:left;width:33%;">&nbsp;</div>'+
					'<div style="float:left;width:33%;"><span class="kheader">Issued Date: </span>'+(invoices[i].IssuedDate==undefined?"":invoices[i].IssuedDate)+'</div>'+
					'<div style="float:left;width:33%;"><span class="kheader">Accountant: </span>'+(invoices[i].AccountantName==undefined?"":invoices[i].AccountantName)+'</div>'+
					(invoices[i].FullyPaidDate!=undefined?'<div class="PaidMessage">'+invoices[i].FullyPaidDate+'</div>':'<div class="ErrorSmall">Unpaid</div>')+
					'</div></div>');
				}
			}else{
				invoicesContainer.append('<div class="InvoiceCard"><div class="Warning">No Invoice Found</div></div>');
			}
		},
		error:function(xhr,status,error){
			//alert('Error:'+error);
		}
	});
});
</script>
</head>
<body>
<%@include file="/WEB-INF/dashboardnavigation.jsp" %>
<div id="OverdueServicesContainer" style="float:left;width:48%;margin-bottom:10px;margin-top:-20px;">
<h2>SERVICES</h2>
<div id="ServiceFiltersContainer" style="float:left;width:100%;margin-bottom:10px;margin-left:18px;">
Filters:
<input id="FilterCompleted" name="FilterCompleted" type="checkbox" checked="checked"/><label for="FilterCompleted">Completed</label>
<input id="FilterIncomplete" name="FilterIncomplete" type="checkbox" checked="checked"/><label for="FilterIncomplete">Incomplete</label>
<input id="FilterBillable" name="FilterBillable" type="checkbox" checked="checked"/><label for="FilterBillable">Billable</label>
<input id="FilterNonBillable" name="FilterNonBillable" type="checkbox" checked="checked"/><label for="FilterNonBillable">Non-Billable</label>
</div>
<div id="ServicesContainer" style="float:left;width:100%;">
</div>
</div>
<div id="OverdueInvoicesContainer" style="float:left;width:48%;margin-bottom:10px;margin-top:-20px;">
<h2>INVOICES</h2>
<div id="InvoiceFiltersContainer" style="float:left;width:100%;margin-bottom:10px;margin-left:18px;">
Filters:
<input id="FilterPaid" name="FilterPaid" type="checkbox" checked="checked"/><label for="FilterPaid">Paid</label>
<input id="FilterUnpaid" name="FilterUnpaid" type="checkbox" checked="checked"/><label for="FilterUnpaid">Unpaid</label>
</div>
<div id="InvoicesContainer" style="float:left;width:100%;">
</div>
</div>
</body>
</html>